﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Diet;
using Logic;

namespace TP5
{
    public partial class Салат : Form
    {
        public bool Check (TextBox box)
        {
            if ((box.Text == "") || (box.Text == "0"))
            {
                box.Text = "0";
                return true;
            }
            else
                return false;
        }
        calorificCalculator calculate = new calorificCalculator();
        public Салат()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            

            if (Check(TomatoBox) == true && Check(OnionBox) == true && Check(PotatoBox) == true && Check(CarrotBox) == true) 
            {
                label8.Text = "";
                label7.Text = "";
                label7.Text = "Салат собрать нельзя";
            }
            else
            {
                label7.Text = "";
                label8.Text = "";
                Salad salad = calorificFactory.CreateSalad(int.Parse(OnionBox.Text), int.Parse(PotatoBox.Text), int.Parse(CarrotBox.Text), int.Parse(TomatoBox.Text));
                label7.Text = "Калорийность салата:  " + calculate.Calculate(salad).ToString();
                label8.Text = "Цена салата:  " + calculate.price(salad).ToString();
            }
        }

        private void TomatoBox_TextChanged(object sender, EventArgs e)
        {
            double num = 0.0;
            if (double.TryParse(TomatoBox.Text, out num))
            {
                TomatoBox.Text = TomatoBox.Text;
            }
            else
            {
                TomatoBox.Clear();
            }
            
        }
        private void CheckEnter ()
        {
            double num = 0.0;
            if (double.TryParse(OnionBox.Text, out num))
            {
                OnionBox.Text = OnionBox.Text;
            }
            else
            {
                OnionBox.Clear();
            }
        }
        private void OnionBox_TextChanged(object sender, EventArgs e)
        {
            double num = 0.0;
            if (double.TryParse(OnionBox.Text, out num))
            {
                OnionBox.Text = OnionBox.Text;
            }
            else
            {
                OnionBox.Clear();
            }
        }

        private void PotatoBox_TextChanged(object sender, EventArgs e)
        {
            double num = 0.0;
            if (double.TryParse(PotatoBox.Text, out num))
            {
                PotatoBox.Text = PotatoBox.Text;
            }
            else
            {
                PotatoBox.Clear();
            }
        }

        private void CarrotBox_TextChanged(object sender, EventArgs e)
        {
            double num = 0.0;
            if (double.TryParse(CarrotBox.Text, out num))
            {
                CarrotBox.Text = CarrotBox.Text;
            }
            else
            {
                CarrotBox.Clear();
            }
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (PotatoBox.Text != "")
            {
                PotatoCount.Text = calorificFactory.PotaloCalory(int.Parse(PotatoBox.Text)).ToString();
            }
            if (CarrotBox.Text != "")
            {
                CarrotCount.Text = calorificFactory.CarrotCalory(int.Parse(CarrotBox.Text)).ToString();
            }
            if (OnionBox.Text != "")
            {
                OnionCount.Text = calorificFactory.OnionCalory(int.Parse(OnionBox.Text)).ToString();
            }
            if (TomatoBox.Text != "")
            {
                TomatoCount.Text = calorificFactory.TomatoCalory(int.Parse(TomatoBox.Text)).ToString();
            }
        }
    }
}
